package net.huashitong.oversee.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.oversee.dao.SupervisionLogDao;
import net.huashitong.oversee.entity.SupervisionLog;
import net.huashitong.oversee.entity.TaskMethon;
import net.huashitong.oversee.filter.SupervisionTaskFilter;
import net.huashitong.oversee.filter.TaskLogFilter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 催办记录serviec
 */
import java.util.List;

/**
 * 催办记录service
 */

@Service
public class SupervisionLogService extends StringPKService<SupervisionLog> {

    @Autowired
    private SupervisionLogDao dao;
    @Autowired
    private TaskMethonService menthonService;
    @Autowired
    SysTableService tableService;

    @Override
    protected BaseDao<SupervisionLog, String> getDao() {
        return dao;
    }

    /**
     * 条件查询催办记录
     *
     * @param
     * @return List<SupervisionLog>
     */
    public List<SupervisionLog> getMissionLog(String id) {
        return dao.getMissionLog(id);
    }

    @Override
    protected void beforeSave(SupervisionLog obj) {
        obj.setSysId(tableService.updateMaxSysId("t_supervision_log", null));
    }

    public List<SupervisionLog> querySupervisionLogs(TaskLogFilter filter) {
        return dao.querySupervisionLogs(filter);
    }

    /**
     * 保存催办记录
     *
     * @param filter
     */
    public boolean saveCuiBanLog(TaskLogFilter filter) {
        if (StringUtils.isBlank(filter.getSupervisionAsk())) {
            System.out.println("记录填写不规范");
            return false;
        } else {
            SupervisionLog logs = new SupervisionLog();
            BeanUtils.copyProperties(filter, logs);
            if(StringUtils.isNotBlank(filter.getMethonCode())){
                TaskMethon method = menthonService.getMethon(filter.getMethonCode());
                if(ObjectUtils.isNotBlank(method)){
                    logs.setMethonName(method.getMethonName());
                }
            }
            save(logs);
            return true;
        }
    }
}
